//
//  AppDelegate.m
//  torycoupon
//
//  Created by 이 민우 on 13. 4. 19..
//  Copyright (c) 2013년 manytory. All rights reserved.
//

#import "AppDelegate.h"
#import "ChoiceViewController.h"
#import "MallViewController.h"
#import "CouponBoxViewController.h"
#import "FriendViewController.h"
#import "SettingViewController.h"

#import "ComData.h"

@implementation AppDelegate

- (void)dealloc
{
    [_window release];
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    
    [self performSelector:@selector(initView)];
    
    return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application
{
}

- (void)applicationDidEnterBackground:(UIApplication *)application
{
}

- (void)applicationWillEnterForeground:(UIApplication *)application
{
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
}

- (void)applicationWillTerminate:(UIApplication *)application
{
}

- (void)initView {
    choiceViewCtrl = [[[ChoiceViewController alloc] init] autorelease];
    toryNaviCtrl = [[[UINavigationController alloc] initWithRootViewController:choiceViewCtrl] autorelease];
    
    mallViewCtrl = [[[MallViewController alloc] init] autorelease];
    UINavigationController *mallNaviCtrl = [[[UINavigationController alloc] initWithRootViewController:mallViewCtrl] autorelease];
    
    couponBoxViewCtrl = [[[CouponBoxViewController alloc] init] autorelease];
    UINavigationController *cpBoxNaviCtrl = [[[UINavigationController alloc] initWithRootViewController:couponBoxViewCtrl] autorelease];
    
    friendViewCtrl = [[[FriendViewController alloc] init] autorelease];
    UINavigationController *friendNaviCtrl = [[[UINavigationController alloc] initWithRootViewController:friendViewCtrl] autorelease];
    
    settingViewCtrl = [[[SettingViewController alloc] init] autorelease];
    UINavigationController *settingNaviCtrl = [[[UINavigationController alloc] initWithRootViewController:settingViewCtrl] autorelease];
    
    toryTabBarCtrl = [[UITabBarController alloc] init];
    toryTabBarCtrl.viewControllers = [NSArray arrayWithObjects:mallNaviCtrl, cpBoxNaviCtrl, friendNaviCtrl, settingNaviCtrl, nil];
    
    if([ComData getPushKey] == nil) {
        self.window.rootViewController = toryNaviCtrl;
    } else {
        self.window.rootViewController = toryTabBarCtrl;
    }
}

@end
